﻿@model Zor_Web.Models.Base.V_Zor_Building
@using Webdiyer.WebControls.Mvc;
@using Zor_Tools;
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>街道信息</title>
    <link href="~/Content/LayerUI/src/css/layui.css" rel="stylesheet" />
    <link href="~/Content/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <link href="~/Content/Styles/zor.css" rel="stylesheet" />
    <!-- 框架必要 -->
    <script src="~/Content/Scripts/jquery/jquery-1.9.1.min.js"></script>
    <script src="~/Content/Scripts/learunui-framework.js"></script>
    <script src="~/Content/Scripts/Zor_AJax.js"></script>
    <!-- 消息提示 -->
    <script language='javascript' src='~/Content/layer/layer.js'></script>
    <!-- 表单验证 -->
    <script src="~/Content/Scripts/JValidator.js"></script>
    <!-- 上传 -->
    <script src="~/Content/Scripts/webuploader/webuploader.min.js"></script>
    <script src="~/Content/Scripts/uploader.js"></script>
    <!-- 表单验证 -->
    <script src="~/Content/Scripts/JValidator.js"></script>
</head>
<body class="gray-bg">
    <div class="layui-tab layui-tab-brief main-tab-container ">
        <div class="col-sm-12 ct-padding">
            <div class="col-sm-9 ct-padding">
                <button id="btnAdd" class="layui-btn layui-btn layui-btn-small"><span class="glyphicon glyphicon-plus"></span> 新增</button>
                <button id="btnUpdate" class="layui-btn layui-btn-warm layui-btn-small"><span class="glyphicon glyphicon-pencil"></span> 编辑</button>
                <button id="btnDelete" class="layui-btn layui-btn-danger layui-btn-small"><span class="glyphicon glyphicon-trash"></span> 删除</button>
                <button id="btnSearch" class="layui-btn layui-btn-normal layui-btn-small"><span class="glyphicon glyphicon-search"></span> 查询</button>
                <button id="btnReplace" class="layui-btn layui-btn-blue layui-btn-small"><span class="glyphicon glyphicon-refresh"></span> 刷新</button>             
                <button id="btnExport" class="layui-btn layui-btn-springgreen  layui-btn-small"><span class="glyphicon glyphicon-share"></span> 导出</button>
                <button id="btnMessage" class="layui-btn layui-btn-orchid layui-btn-small"><span class="glyphicon glyphicon-list-alt"></span> 详情</button>
            </div>
        </div>
        <div class="layui-tab-content">
            <table class="layui-table" lay-skin="line">
                <thead>
                    <tr>
                        <th hidden></th>
                        <th></th>
                        <th hidden>所属社区</th>
                        <th>街道(楼宇)名称</th>
                        <th>管理员姓名</th>
                        <th>管理员性别</th>
                        <th>管理员身份证号</th>
                        <th>管理员电话</th>
                        <th>创建时间</th>
                    </tr>
                </thead>
                <tbody id="accordion">
                    @foreach (var item in Model.PageData)
                    {
                        if (@item.Bd_Aname == null && @item.Sex == null && @item.Bd_IDNumber == null)
                        {
                        <tr>
                            <td hidden>@item.Bd_Id</td>
                            <td><input type="radio" name="chk" id="@item.Bd_Id" value="@item.Bd_Id" /></td>
                            <td hidden>@item.Dt_Id</td>
                            <td> <span class='label label-warning pull-center'>请将（@item.Bd_Name）信息补充完整</span></td>
                            <td>@item.Bd_Aname</td>
                            <td>@item.Sex</td>
                            <td>@item.Bd_IDNumber</td>
                            <td>@item.Bd_Telephone</td>
                            <td>@TimeHelper.TimeStampToDateTime(item.Bd_CreateDate.ToString(), TimeHelper.ToTimeType.link_ymd)</td>
                            <td hidden>@item.Bd_Sex</td>
                            <td hidden>@item.Dt_Name</td>
                        </tr>
                    }
                    else { 
                         <tr>
                            <td hidden>@item.Bd_Id</td>
                            <td><input type="radio" name="chk" id="@item.Bd_Id" value="@item.Bd_Id" /></td>
                            <td hidden>@item.Dt_Id</td>
                            <td>@item.Bd_Name</td>
                            <td>@item.Bd_Aname</td>
                            <td>@item.Sex</td>
                            <td>@item.Bd_IDNumber</td>
                            <td>@item.Bd_Telephone</td>
                            <td>@TimeHelper.TimeStampToDateTime(item.Bd_CreateDate.ToString(), TimeHelper.ToTimeType.link_ymd)</td>
                            <td hidden>@item.Bd_Sex</td>
                            <td hidden>@item.Dt_Name</td>
                        </tr>
                         }
                    }
                </tbody>
            </table>
            <div class="col-sm-12">
                <div class="col-sm-10">
                    @Html.Pager(Model.PageData, new PagerOptions { PageIndexParameterName = "index", ContainerTagName = "ul", PrevPageText = "上页", NextPageText = "下页", FirstPageText = "首页", LastPageText = "尾页", CssClass = "pagination", PagerItemsSeperator = "", CurrentPagerItemWrapperFormatString = "<li class=\"active\"><a href=\"#\">{0}</a></li>", PagerItemWrapperFormatString = "<li>{0}</li>" }, new { id = "", @class = "pagination" })
                </div>
                <div class="col-sm-2 to-righjt">
                    共 @Model.PageData.TotalItemCount 条记录，页 @Model.PageData.CurrentPageIndex/@Model.PageData.TotalPageCount
                </div>
                <div id="page" class="col-md-7 col-sm-offset-5 text-center"></div>
            </div>
        </div>

    </div>

    @using (Html.BeginForm("Zor_Street", "Base", new RouteValueDictionary { { "Model", Model } }, FormMethod.Get))
    {
    <!-- 查询模态框 -->
    <div id="myModalSearch" hidden data-backdrop="static">
        <div id="divselectfrom" class="layui-tab-content">
            <form class="form-horizontal m-t">
                <div class="layui-form-item">
                    <label class="col-sm-3 layui-form-label">街道(楼宇)名称：</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control" name="Bd_Name" value="@Model.Bd_Name">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="col-sm-3 layui-form-label">管理员姓名：</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control" name="Bd_Aname" value="@Model.Bd_Aname">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="col-sm-3 layui-form-label">管理员身份证：</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control" name="Bd_IDNumber" value="@Model.Bd_IDNumber">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="col-sm-3 layui-form-label">管理员电话：</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control" name="Bd_Telephone" value="@Model.Bd_Telephone">
                    </div>
                </div>
            </form>
            <div class="box-footer">
                <button type="submit" class="btn btn-info pull-right">
                    <i class="fa fa-search"></i>查询
                </button>
            </div>
        </div>
    </div>

    }
    <!-- 新增修改模态 -->
    <div id="myModal" hidden data-backdrop="static">
        <div id="divfrom" class="layui-tab-content">
            <form class="form-horizontal m-t">

                <div class="layui-form-item" hidden>
                    <label class="col-sm-3 layui-form-label">ID：</label>
                    <div class="col-sm-9">
                        <input id="Bd_Id" type="text" class="form-control">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="col-sm-3 layui-form-label">所属社区：</label>
                    <div class="col-sm-9">
                        <select name="temp" class="form-control" disabled="" id="Dt_Id"></select>
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="layui-form-item">
                    <label class="col-sm-3 layui-form-label">街道(楼宇)名称：</label>
                    <div class="col-sm-9">
                        <input id="Bd_Name" type="text" class="form-control" autofocus="autofocus" datacol="yes" err="街道名称" checkexpession="NotNull">
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="layui-form-item">
                    <label class="col-sm-3 layui-form-label">管理员姓名：</label>
                    <div class="col-sm-9">
                        <input id="Bd_Aname" type="text" class="form-control" autofocus="autofocus" datacol="yes" err="管理员姓名" checkexpession="ChineseStrOrNull">
                    </div>
                </div>
                <div class="hr-line-dashed"></div>

                <div class="layui-form-item">
                    <label class="col-sm-3 layui-form-label">管理员性别：</label>
                    <div class="col-sm-9">
                        <input type="radio" value="1" id="Bd_sex_yes" name="sex" checked>男
                        &nbsp;&nbsp;&nbsp;
                        <input type="radio" value="2" id="Bd_sex_no" name="sex">女
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="layui-form-item">
                    <label class="col-sm-3 layui-form-label">管理员身份证：</label>
                    <div class="col-sm-9">
                        <input id="Bd_IDNumber" type="text" class="form-control" autofocus="autofocus" datacol="yes" err="管理员身份证" checkexpession="IDCard">
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="layui-form-item">
                    <label class="col-sm-3 layui-form-label">管理员电话：</label>
                    <div class="col-sm-9">
                        <input id="Bd_Telephone" type="text" class="form-control" autofocus="autofocus" datacol="yes" err="管理员电话" checkexpession="MobileOrPhone">
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="layui-form-item">
                    <label class="col-sm-3 layui-form-label">管理员照片：</label>
                    <div class="col-sm-3">
                       
                        <div class="upload-box upload-img"></div>
                        <div style="width:80px;height:100px;margin-top:10px;"><img id="ImgFile" style="width: 80px; height: 100px;" class="upload-show0" src="" alt="" /></div>
                    </div>
                    <input id="Bd_PhotoPath" type="hidden"  class="form-control upload-path0" autofocus="autofocus" style="width: 348px; display: inline;" readonly>
                </div>
            </form>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="form-group">
            <div class="col-sm-11 ">
                <button type="submit" id="btnSure" class="btn btn-info pull-right">
                    <i class="fa fa-check"></i>提交
                </button>
            </div>
        </div>
    </div>

    <!-- 详情模态 -->
    <div id="myModalMessage" hidden data-backdrop="static">
        <div id="divfrom" class="ibox float-e-margins">
            <div class="modal-body">
                <form class="form-horizontal m-t">
                    <div>
                        <label class="col-sm-4 layui-form-label">所属社区：</label>
                        <div class="col-sm-7 layui-input" id="Dt_Name1">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="col-sm-4 layui-form-label">街道(楼宇)名称：</label>
                        <div class="col-sm-7 layui-input" id="Bd_Name1">
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="layui-form-item">
                        <label class="col-sm-4 layui-form-label">管理员姓名：</label>
                        <div class="col-sm-7 layui-input" id="Bd_Aname1">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="col-sm-4 layui-form-label">管理员性别：</label>
                        <div class="col-sm-7 layui-input" id="Bd_Sex1">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="col-sm-4 layui-form-label">管理员身份证：</label>
                        <div class="col-sm-7 layui-input" id="Bd_IDNumber1">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="col-sm-4 layui-form-label">管理员电话：</label>
                        <div class="col-sm-7 layui-input" id="Bd_Telephone1">
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
         
    <!-- 导出模态 -->
    <form action="/Base/ExportStreet" enctype="multipart/form-data" method="post" id="formDownload">
        <div id="exportHtml" style="display:none;">
            <div class="eh_wrap">
                <div class="eh_head">
                    <p style="">请选择您要导出的数据列</p>
                </div>
                <table width="100%" cellpadding="5" cellspacing="0">
                    <tr>
                        <td><input id="Dt_Name" type="checkbox" value="所属部门" name="chk_list" checked="checked" /><label>所属部门</label></td>
                        <td><input id="Bd_Name" type="checkbox" value="街道(楼宇)名称" name="chk_list" checked="checked" /><label>街道名称</label></td>
                        <td><input id="Bd_Aname" type="checkbox" value="管理员名称" name="chk_list" checked="checked" /><label>管理员名称</label></td>
                        <td><input id="Sex" type="checkbox" value="管理员性别" name="chk_list" checked="checked" /><label>管理员性别</label></td>
                    </tr>
                    <tr>
                        <td><input id="Bd_IDNumber" type="checkbox" value="管理员身份证号" name="chk_list" checked="checked" /><label>管理员身份证号</label></td>
                        <td><input id="Bd_Telephone" type="checkbox" value="管理员电话" name="chk_list" checked="checked" /><label>管理员电话</label></td>
                        <td><input id="Bd_CreateDate" type="checkbox" value="创建时间" name="chk_list" checked="checked" /><label>创建时间</label></td>
                    </tr>
                </table>
                <div class="box-footer">
                    <button type="submit" id="btnExportSure" class="btn btn-info pull-right">
                        <i class="fa fa-repeat"></i>导出
                    </button>
                    <input type="hidden" id="buildingMeg" name="buildingMeg" value="" />
                    <input type="hidden" id="where" name="where" value="" />
                </div>
            </div>
        </div>
    </form>
</body>

</html>
<script>
    /**
     * 获取所属部门名称
     */
    function GetDtName() {
        var html = "";
        getAjax("/Base/GetDtName", "", function (data) {
            accordionJson = eval("(" + data + ")");
            $.each(accordionJson, function (i) {
                html += "<option value='" + accordionJson[i].Dt_Id + "' >" + accordionJson[i].Dt_Name + "</option>";
                
            });
        });
        $("#Dt_Id").empty().append(html);
    }


    //获取选中的性别
    function SaveAdmin() {
        var radio = $('input[name = "sex"]').filter(':checked');
        radio.attr("ID", "Bd_Sex");
    }


    //查询
    $(function () {
        $("#btnSearch").click(function () {
            ClearWebControls(divfrom);
            LayerOpen('550px', '300px', '街道查询', $('#myModalSearch'));
        })
    })


        /**
        * 增加街道
        */
        $(function () {
            $("#btnAdd").click(function () {
                ClearWebControls(divfrom);
                GetDtName();
                LayerOpen('600px', '550px', '街道新增', $('#myModal'));
            })
        })

        /**                                                                 
        * 修改街道                                                          
        */
        $(function () {
            $("#btnUpdate").click(function () {
                var checkId = CheckboxValueIDs();
                var Dt_Id = getTableCell(2);
                var Street_Name = getTableCell(3);
                var Street_Aname = getTableCell(4);
                var Street_Sex = getTableCell(9);
                var Street_IDNumber = getTableCell(6);
                var Street_Telephone = getTableCell(7);
                $("#lbltitle").text("修改街道");
                $("#Bd_Id").attr("disabled", "disabled");
                if (checkId.length == 0) {
                    layer.msg("请选择要修改的街道！");
                    return;
                }
                if (checkId.length > 1) {
                    layer.msg("仅可选择一行信息修改！");
                    return;
                }
               
                GetDtName();
                $("#Bd_Id").val(checkId[0]);
                $("#Dt_Id").val(Dt_Id);
                $("#Bd_Name").val(Street_Name);
                $("#Bd_Aname").val(Street_Aname);
                $("#Bd_Sex").val(Street_Sex);
                $("#Bd_IDNumber").val(Street_IDNumber);
                $("#Bd_Telephone").val(Street_Telephone);
                LayerOpen('600px', '550px', '街道修改', $('#myModal'));
            })
        })

      /**
      * 街道详情
      */
        $(function () {
            $("#btnMessage").click(function () {
                var checkId = CheckboxValueIDs();                                  
                var Dt_Name1 = getTableCell(10);    
                var Bd_Name1 = getTableCell(3);    
                var Bd_Aname1 = getTableCell(4);    
                var Bd_Sex1 = getTableCell(9);    
                var Bd_IDNumber1 = getTableCell(6); 
                var Bd_Telephone1 = getTableCell(7);
                $("#lbltitle").text("修改街道");     
                $("#Bd_Id1").attr("disabled", "disabled");                       
                if (checkId.length == 0) {                                      
                    layer.msg("请选择要查看的街道！");                             
                    $("#myModalMessage").attr("ID", "test");                    
                    return;
                }
                if (checkId.length > 1) {
                    layer.msg("仅可选择一栋街道查看！");
                    $("#myModalMessage").attr("ID", "test");
                    return;
                }
                $("#test").attr("ID", "myModalMessage");
                $("#Bd_Id1").html(checkId[0]);
                $("#Dt_Name1").html(Dt_Name1);
                $("#Bd_Name1").html(Bd_Name1);
                $("#Bd_Aname1").html(Bd_Aname1);
                $("#Bd_Sex1").html(Bd_Sex1);
                $("#Bd_IDNumber1").html(Bd_IDNumber1);
                $("#Bd_Telephone1").html(Bd_Telephone1);
                LayerOpen('530px', '350px', '街道详情', $('#myModalMessage'));
            })
        })


        /**                                                                       
    * 删除街道
    */
        $(function () {
            $("#btnDelete").click(function () {
                var checkId = CheckboxValueIDs();
                if (checkId.length == 0) {
                    layer.msg("请选择要删除的街道！");                                   
                    return;
                }
                else {
                    layer.confirm("确定要删除吗?", { icon: 2, btn: ['确定', '取消'] }, function () {
                        ZorPostSimpleData("/Base/DeleteStreet", JSON.stringify({ 'id': checkId }), function (data) { //获取数据(带参数)
                            layer.msg(data.AnswerMeg, function () {
                                layer.closeAll();
                                Replace();
                            });
                        })
                    })
                }
            })
        })

    /**
    * 刷新
    **/
    $(function () {
        $("#btnReplace").click(function () {
            Replace();
        })
    })

    /**
    * 保存
    */
    $(function () {
        $("#btnSure").click(function () {
            if (!CheckDataValid('.form-horizontal')) {
                return false;
            }
            SaveAdmin();
            var JsData = GetWebControls(divfrom);
            ZorPostSimpleData("/Base/AddStreet", JSON.stringify({ "street": JsData }), function (data) {
                layer.msg(data.AnswerMeg, function () {
                    layer.closeAll();
                    Replace();

                });
            })
        })
    })
        /**
        * 模态关闭后回调用
        */
        $(function () {
            $('#myModal').on('hidden.bs.modal', function (e) {
                Replace();
            })
        })


        /**
        * 全选
        */
        $(function () {
            $("#cbkCheckAll").click(function () {
                if (this.checked) {
                    $("input[name='chk']").prop('checked', true);
                } else {
                    $("input[name='chk']").prop('checked', false);
                }
            })
        })

        /*导出*/
        $("#btnExport").click(function () {
            layer.open({
                type: 1,
                title: '导出提示',
                shade: false,
                skin: 'layui-layer-rim',
                area: ['620px', '240px'], //宽高
                content: $('#exportHtml')
            });
        });
        /*导出交互*/
        $("#btnExportSure").click(function () {
            var arr = new Array();
            $("[name='chk_list']").each(function () {
                if ($(this).is(":checked")) {
                    arr.push($(this).attr("id") + "|" + $(this).val());
                }
            });
            $("#buildingMeg").val(arr);
            document.getElementById('formDownload').submit();
            layer.closeAll();
        });

        $(function () {
            //初始化上传控件
            $(".upload-img").InitUploader({
                sendurl: "../tools/UploadServer.ashx", swf: "../Content/Scripts/webuploader/uploader.swf", thumbnail: true, filetypes: "jpg,png,gif", actionflag: "UpLoadImg"
            });
        })
  
</script>

